package com.zju.cst.cloudApp.command.impl;

import com.zju.cst.cloudApp.command.CodeAnnotation;
import com.zju.cst.cloudApp.entity.HostInfo;
import com.zju.cst.cloudApp.entity.Message;
import com.zju.cst.cloudApp.service.HostService;
import com.zju.cst.cloudApp.util.Constants;
import com.zju.cst.cloudApp.util.ParamsKey;

public class HostManageHandler extends BasicHandler {

	private HostService hostService;
	
	/**
	 * 注册物理机,runstatus=HOST_RUNSTATUS_REGISTE
	 * @param message
	 * @return
	 */
	@CodeAnnotation(code = "10000001")
	public Message registerHost(Message message) {
		System.out.println(message.getUserId());
		HostInfo hostInfo = new HostInfo();
		hostInfo.setName((String)message.getParam(ParamsKey.HOST_NAME));
		hostInfo.setCpuInit(Double.parseDouble((String)message.getParam(ParamsKey.HOST_CPU_INIT)));
		hostInfo.setMemInit(Double.parseDouble((String)message.getParam(ParamsKey.HOST_MEM_INIT)));
		hostInfo.setDiskInit(Double.parseDouble((String)message.getParam(ParamsKey.HOST_DISK_INIT)));
		hostInfo.setIp((String)message.getParam(ParamsKey.HOST_IP));
		hostInfo.setComments((String)message.getParam(ParamsKey.HOST_COMMENTS));
		hostInfo.setEnable(true);
		hostInfo.setRunstatus(Constants.HOST_RUNSTATUS_REGISTE);
		hostService.registerHost(hostInfo);
		return null;
	}

	/**
	 * AGENT 返回注册物理机成功,runstatus=HOST_RUNSTATUS_AGENT_CHECKED
	 * @param message
	 * @return
	 */
	@CodeAnnotation(code = "10000002")
	public Message method2(Message message) {
		String hostIp = (String)message.getParam(ParamsKey.HOST_IP);
		HostInfo hostInfo = new HostInfo();
		hostInfo.setRunstatus(Constants.HOST_RUNSTATUS_AGENT_CHECKED);
		return null;
	}

	//-----------------------------------------
	public HostService getHostService() {
		return hostService;
	}

	public void setHostService(HostService hostService) {
		this.hostService = hostService;
	}
	
}